import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/auto_makers/shop_home/my_order.dart';
import 'package:ytbusiness/page/auto_makers/shop_home/shop_comment.dart';
import 'package:ytbusiness/page/drawer/draw_layout.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

///汽配商主页
class ShopHomePage extends StatefulWidget {
  @override
  _ShopHomePageState createState() => _ShopHomePageState();
}

class _ShopHomePageState extends State<ShopHomePage> {
  List<String> numList=["5","20000","7","8","100","3","8","100","3","3","8","100","3"];
  List<String> titleList=["待报价","已报价","等待付款","待发货","已发货","待开票","已开票","已退票","待结算","已结算","已取消","退款中","已退款"];
  DateTime _lastPressedAt; //上次点击时间
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        if (_lastPressedAt == null ||
            DateTime.now().difference(_lastPressedAt) > Duration(seconds: 1)) {
          //两次点击间隔超过1秒则重新计时
          _lastPressedAt = DateTime.now();
          return false;
        }
        return true;
      },
      child: Scaffold(
        backgroundColor: Color(0xffF0F0F0),
        appBar: AppBar(
          elevation: 0,
          centerTitle: true,
//          backgroundColor: YTTheme.theme,
          backgroundColor: YTTheme.theme,
          title: Text("云途养护",style: TextStyle(color: Colors.white,fontSize: setSp(19)),),
          leading: Builder(builder: (BuildContext context){
            return GestureDetector(
              onTap: (){
                Scaffold.of(context).openDrawer();

              },
              child: Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(left: setWidth(15)),
                    width: setWidth(33),
                    height: setWidth(33),
                    decoration: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage("assets/images/touxiang.png"),fit: BoxFit.cover,
                        ),
                        borderRadius: BorderRadius.circular(25)
                    ),
                  ),
                ],
              ),
            );

          },),
          actions: [
            Row(
              children: [
                GestureDetector(
                  onTap: (){
                    urlPush(context, "yuntu://message_center");
                  },
                  child: Container(
                    width: setWidth(22),
                    height: setWidth(21),
                    child: Image.asset("assets/images/message.png"),
                  ),
                ),
                SizedBox(
                  width: setWidth(20),
                )
              ],
            )
          ],
        ),
        //抽屉
        drawer:DrawerLayout(),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              SizedBox(
                height: setWidth(15),
              ),
              Container(
                padding: EdgeInsets.only(top: setWidth(17),bottom: setWidth(17),left: setWidth(15),right: setWidth(15)),
                color: Colors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Row(
                      children: [
                        Container(
                          height: setWidth(50),
                          width: setWidth(60),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(3),
//                              image: DecorationImage(
//                                  image: NetworkImage("https://i.loli.net/2020/11/25/e8H2umapcJO7Zyo.png"),fit: BoxFit.cover
//                              )
                          ),
                          child:Image.asset("assets/images/car.png",fit: BoxFit.cover) ,
                        ),
                        SizedBox(
                          width: setWidth(10),
                        ),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text("云达汽贸",style: TextStyle(color: Color(0xff323232),fontSize: setSp(16)),),
                            SizedBox(
                              height: setWidth(12),
                            ),
                            Text("宝马奥迪本田汽配中心",style: TextStyle(color: Color(0xff999999),fontSize: setSp(12)),),
                          ],
                        ),
                      ],
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          height: setWidth(13),
                          width: setWidth(11),
                          child: Image.asset("assets/images/location.png",fit:BoxFit.cover,color: YTTheme.theme,),
                        ),
                        SizedBox(
                          width: setWidth(10),
                        ),
                        Text("安徽 合肥",style: TextStyle(color: YTTheme.theme,fontSize: setSp(12)),),
                      ],
                    )

                  ],
                ),
              ),
              SizedBox(
                height: setWidth(15),
              ),
              _textBanner(),
              Container(
                padding: EdgeInsets.only(top:setWidth(20),bottom:setWidth(20),left: setWidth(15),right: setWidth(15)),
                color: Colors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      child:Text("账户余额",style: TextStyle(color: Color(0xff333333),fontSize: setSp(15),fontWeight: FontWeight.w600),),
                    ),
                    Container(
                      child:Text("389.00",style: TextStyle(color: Color(0xff333333),fontSize: setSp(23),fontWeight: FontWeight.w600),),
                    ),

                  ],
                ),
              ),
              SizedBox(
                height: setWidth(15),
              ),
              //我的订单
              MyOrder(numList: numList,titleList: titleList),
              SizedBox(
                height: setWidth(15),
              ),
              //店铺评论
              Container(
                color: Colors.white,
                padding: EdgeInsets.only(top: setWidth(15),bottom: setWidth(13)
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      child:Text("店铺评论",style: TextStyle(color: Color(0xff323232),fontSize: setSp(17),fontWeight: FontWeight.w400),),
                    ),
                  ],
                ),
              ),
              ShopComment(),
            ],
          ),
        ),
      ),
    );
  }

  //文字轮播
  Widget  _textBanner() {
    return Container(
      padding: EdgeInsets.only(top: setWidth(10),left: setWidth(10),right: setWidth(10),bottom: setWidth(10)),
      decoration: BoxDecoration(
          color: Colors.white,
      ),
      height: setWidth(40),
      child: Swiper(
        autoplay: true,
        scrollDirection:Axis.vertical,
        physics: NeverScrollableScrollPhysics(),
        duration: 1000,
        itemBuilder: (BuildContext context, int index) {
          return RichText(text: TextSpan(
              children: [
                WidgetSpan(
                  child:Container(
                    child: Image.asset("assets/images/notice.png",width: setWidth(25),height: setWidth(16),fit: BoxFit.cover,color: YTTheme.theme,),
                    margin: EdgeInsets.only(right: setWidth(8)),
                  ),
                ),
                TextSpan(
                    text: "促销活动报名进行中...",style: TextStyle(color: Color(0xff646464),fontSize: setSp(14))
                ),
              ]
          ));
        },
        itemCount: 3,
      ),
    );
  }
}
